package com.acando.mate.view;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.acando.mate.NewsAdapter;
import com.acando.mate.R;
import com.acando.mate.R.array;
import com.acando.mate.R.id;
import com.acando.mate.R.layout;
import com.acando.mate.WorkersAdapter;
import com.acando.mate.models.Worker; 

import android.app.Fragment;
import android.app.ListFragment;
import android.opengl.Visibility;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class WorkersFragment extends Fragment {

	private View mSelectedView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View v = inflater.inflate(R.layout.workers_fragment, container, false);

		// Retrieving the currently selected item number
		int position = getArguments().getInt("position");

		// List of rivers
		String[] menus = getResources().getStringArray(R.array.menus);

		// Updating the action bar title
		getActivity().getActionBar().setTitle(menus[position]);

		// Initializing and loading url in webview
		ListView listView = (ListView) v.findViewById(R.id.workerslistView);
		WorkersAdapter workersAdapter = new WorkersAdapter(getActivity(),
				new ArrayList<Worker>());
		workersAdapter.add(Worker.getDummyWorker());
		workersAdapter.add(Worker.getDummyWorker());
		workersAdapter.add(Worker.getDummyWorker());
		 
		
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				Log.d("asd", "" + v.getId());
				LinearLayout view = (LinearLayout) v
						.findViewById(R.id.workers_details_layout);
				if (view.equals(mSelectedView)) {
					mSelectedView = null;
					view.setVisibility(View.GONE);
				} else {
					if (mSelectedView != null) {
						mSelectedView.setVisibility(View.GONE);
					}
					mSelectedView = view;
					view.setVisibility(View.VISIBLE);
				}
			}
		});
		listView.setAdapter(workersAdapter);

		return v;
	}
	
}
